{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <div class="layui-input-inline">
                <input type="text" placeholder="输入部门名称" name="order_no" lay-verify="required|phone" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn " data-type="reload" ><i class="layui-icon">&#xe615;</i>搜索</button>
            <button class="layui-btn "  id="add">添加部门信息</button>
        </div>
    </blockquote>
    <div class="demoTable layui-for">
        <table class="layui-table" lay-data="{height: 'full-150', url:'{:url('depart/departList')}',edit:true, page:true, id:'testReload',loading:true}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:120}">ID</th>
                <th lay-data="{field:'depart_name',width:120,sort:true}">部门名称</th>
                <th lay-data="{field:'created_ts', width:180, sort:true,sort:true}">创建时间</th>
                <th lay-data="{field:'status', width:100, templet: '#status',sort:true}">状态</th>
                <th lay-data="{fixed:'is_hot', width:210,fixed: 'right', align:'left', toolbar: '#barDemo'}"></th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

        </script>
        <script type="text/html" id="contentTpl" lay-event="detail_content">
            <span>{{ d.describe }}</span>
        </script>
        <script type="text/html" id="status">
            {{#  if(d.status == 1){ }}
            <span>正常</span>
            {{#  } }}
            {{#  if(d.status == 2){ }}
            <span>禁用</span>
            {{#  } }}
        </script>




    </div>
    {include file='common/footer'}
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;
            var $ = layui.$, active = {
                reload: function(){
                    var department_name = $('input[name="order_no"]').val();
                    //执行重载
                    table.reload('testReload', {
                        where: {
                            department_name:department_name,
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });



            //监听表格复选框选择
            table.on('checkbox(demo)', function(obj){
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        title: '编辑',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['100%', '100%'],
                        content:'{:url("depart/saveDepartInfo")}?id='+data.id,
                        end: function () {
                            table.reload('testReload');
                        },
                    });
                }else if(obj.event === 'del'){
                    layer.confirm('确定删除么', function(index){
                        $.ajax({
                            url:'{:url("depart/departDel")}?id='+data.id,
                            type:'get',
                            dataType:'json',
                            success:function(val){
                                if(val.code == 200){
                                    obj.del();
                                    layer.close(index);
                                }
                                if(val.code == 500){
                                    layer.msg(val.msg);
                                }
                            }
                        });

                    });
                }
            });

            $('#add').on('click', function() {
                layer.open({
                    type: 2,
                    title: '添加部门',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['100%', '100%'],
                    content: '{:url("depart/saveDepartInfo")}',
                    end: function () {
                        table.reload('testReload');
                    },
                });
            });
        });
    </script>
    </body>
    </html>